package com.suyang.syt.exception;

/**
 * Copyright (c) 2005-2012 https://github.com/zhangkaitao
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */

import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.servlet.ModelAndView;

/**
 * <p>
 * User: Zhang Kaitao
 * <p>
 * Date: 13-5-7 下午3:38
 * <p>
 * Version: 1.0
 */
@ControllerAdvice
public class DefaultExceptionHandler {

	/**
	 * 没有权限 异常
	 * <p/>
	 * 后续根据不同的需求定制即可
	 */
	@ExceptionHandler({ UnauthorizedException.class })
	@ResponseStatus(HttpStatus.UNAUTHORIZED)
	public ModelAndView processUnauthenticatedException(NativeWebRequest request, UnauthorizedException e) {
		System.out.println("用户权限验证失败");
		ModelAndView mv = new ModelAndView();
		mv.addObject("error", "用户权限验证失败");
		mv.setViewName("error/exception");
		return mv;
	}
}
